home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGSCAL / ANIMATE.LZH / DECIHEX.ASM < prev    next >
Assembly Source File  |  1984-09-14  |  3KB  |  72 lines

  1.           ; from ASSEMBLY LANGUAGE PRIMER FOR THE IBM PC & XT
  2.           ; by Robert LaFore
  3.           ;    modified to be compilable by CHASM  (disk # 37)
  4.           ;MAIN PART OF PROGRAM
  5.           ;Connects procedures together
  6. repeat   call      decibin   ;keyboard to binary
  7.          call      crlf      ;print cr and lf
  8.          call      binihex   ;binary to screen
  9.          call      crlf      ;print cr and lf
  10.          jmps      repeat    ;do it again
  11.  
  12.          ;+++++++++++++++++++++++++++++++++++++++++++
  13.          ;PROCEDURE TO CONVERT DEC ON KEYBD TO BINARY
  14.          ;result is left in bx register
  15. decibin  proc      near
  16.          mov       bx,0      ;clear bx for number
  17.          ; get digit from keyboard, convert to binary
  18. newchar  mov       ah,1      ;keyboard input
  19.          int       21h       ;call DOs
  20.          sub       al,30h    ;ASCII to binary
  21.          jl        exit      ;jump if <0
  22.          cmp       al,9      ;> 9d?
  23.          jg        exit      ;if so, not a dec. digit
  24.          cbw                 ;byte in al to word in ax
  25.          ;(digit is now in ax)
  26.          ;Multiply number in bx by 10 decimal
  27.          xchg      ax,bx     ;trade digit and number
  28.          mov       cx,10     ;put 10d in cx
  29.          mul       ax,cx     ;number times 10 (ChAsm wants "ax")
  30.          xchg      ax,bx     ;trade number and digit
  31.                              ;add digit in ax to number in bx
  32.          add       bx,ax     ;add digit to number
  33.          jmps      newchar   ;get next digit
  34. exit
  35.          ret                 ;return from decibin
  36.          endp
  37.          ;+++++++++++++++++++++++++++++++++++++++++++
  38.          ;PROCEDURE TO CONVERT BINARY NUMBER IN BX TO HEX ONSCREEN
  39.  
  40. binihex   proc      near      ;
  41.           mov       ch,4      ;number of digits
  42. rotate    mov       cl,4      ;set count to 4 bits
  43.           rol       bx,cl     ;left digit to right
  44.           mov       al,bl     ;move to al
  45.           and       al,0fh    ;mask off left digit
  46.           add       al,30h    ;convert to ascii
  47.           cmp       al,3ah    ;is it > 9?
  48.           jl        printit   ;if not, printit
  49.           add       al,7h     ;digit is A to F
  50. printit
  51.           mov       dl,al     ;put ascii chr in dl
  52.           mov       ah,2      ;display output function
  53.           int       21h       ;DOS call
  54.           dec       ch        ;done 4 yet?
  55.           jnz       rotate    ;if not, go back
  56.           ret                 ; return from binihex
  57.           endp
  58.          ;+++++++++++++++++++++++++++++++++++++++++++
  59.          ;PROCEDURE TO PRINT CR AND LF ONSCREEN
  60. crlf     proc      near
  61.          mov       dl,0dh     ;carriage return
  62.          mov       ah,2       ;display function
  63.          int       21h        ;DosCall
  64.          mov       dl,0ah     ;linefeed
  65.          mov       ah,2       ;display function
  66.          int       21h        ;DosCall
  67.          ret                  ;return from crlf
  68.          endp
  69.          ;+++++++++++++++++++++++++++++++++++++++++++
  70.          ;decihex ends
  71.          ;+++++++++++++++++++++++++++++++++++++++++++
  72.